﻿// Write a method that checks if the element at given position 
// in given array of integers is bigger than its two neighbors (when such exist).

using System;

public class BiggerNeighbors
{
    static void Main()
    {
        int[] intArray = { 1, 2, 1 };
        int elementPosition = 1;
        if (IsBiggerThanNeighbors(elementPosition, intArray))
        {
            Console.WriteLine("Element {0} at the position {1} of the Array is bigger than its two neighbors.", intArray[elementPosition], elementPosition);
        }
        else
        {
            Console.WriteLine("Element {0} at the position {1} of the Array is NOT bigger than its two neighbors.", intArray[elementPosition], elementPosition);
        }
    }

    public static bool IsBiggerThanNeighbors(int pos, int[] intArray)
    {
        if (intArray.Length == 0)
        {
            return false;
        }
        else if (intArray.Length == 1)
        {
            return true;
        }
        else
        {
            if (pos == 0)
            {
                return (intArray[pos] > intArray[pos + 1]);
            }
            else if (pos == intArray.Length - 1)
            {
                return (intArray[pos - 1] < intArray[pos]);
            }
            else
            {
                return (intArray[pos - 1] < intArray[pos] && intArray[pos] > intArray[pos + 1]);
            }
        }
    }
}